package com.kaoshi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kaoshi.mapper.NewsMapper;
import com.kaoshi.pojo.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;


    @Override
    public PageInfo<News> getNews(Integer page, Integer pageSize) {
        // 开始分页
        //1、调用PageHelper的startPage方法设置参数,其中page为当前页，size为每页显示条数
        PageHelper.startPage(page,pageSize);
        //2、调用查询全部的方法
        List<News> news = newsMapper.getNews();
        //3、构造pageInfo返回值
        return new PageInfo(news);
    }

    @Override
    public News getNameNews(String name) {
        return newsMapper.getNameNews(name);
    }

    @Override
    public News getIdNews(int id) {
        return newsMapper.getIdNews(id);
    }

    @Override
    public PageInfo<News> selectlinkTitleNews(String title, Integer page, Integer pageSize) {
        // 开始分页
        //1、调用PageHelper的startPage方法设置参数,其中page为当前页，size为每页显示条数
        PageHelper.startPage(page,pageSize);
        //2、调用查询全部的方法
        List<News> news = newsMapper.selectlinkTitleNews(title);
        //3、构造pageInfo返回值
        return new PageInfo(news);
    }


    @Override
    public int addNew(News news) {
        return newsMapper.addNew(news);
    }

    @Override
    public int updateNew(News news) {
        return newsMapper.updateNew(news);
    }

    @Override
    public int deleteNew(int id) {
        return newsMapper.deleteNew(id);
    }
}
